package com.larry.tinyweb.plugin;


import com.larry.tinyweb.core.Global;
import com.larry.tinyweb.core.RequestEntity;

/**
 * Created by larry on 16/9/23.
 *
 * 静态资源插件
 */
public class StaticPlugin implements Plugin {
    @Override
    public void plugin(RequestEntity requestEntity) throws Exception {
        if (statics(requestEntity)) requestEntity.setStatic();
    }


    public boolean statics(RequestEntity requestEntity) {
        StringBuffer requestURL = requestEntity.getRequest().getRequestURL();
        String sub = requestURL.substring(requestURL.lastIndexOf(".")+1);
        if (sub == null || "".equals(sub.trim()) || Global.statics.contains(sub)) {
            requestEntity.stopPlugin();
            return true;
        } else {
            return false;
        }
    }
}
